﻿@using ZR.CodeGenerator
@using ZR.Model.System.Generate
@using Infrastructure.Extensions;
@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genTable = Model.GenTable;
    var genTableOptions=genTable.Options;
    List<GenTableColumn> formCols = genTable.FormColumns;
    var funcCodeFirstLower=genTable.FunctionCode.FirstLowerCase();
    var subTableOptions = Model.SubTableOptions;
    var replaceDto = Model.ReplaceDto;
    bool showCustomInput = Model.GenTable.Columns.Any((Func<GenTableColumn, bool>)(f => f.HtmlType.Equals(GenConstants.HTML_CUSTOM_INPUT, StringComparison.OrdinalIgnoreCase)));
    var dictHtml = new string[] { GenConstants.HTML_CHECKBOX, GenConstants.HTML_RADIO,GenConstants.HTML_RADIO_BTN, GenConstants.HTML_SELECT, GenConstants.HTML_SELECT_MULTI };
    var dicts = new List<GenTableColumn>();
    dicts.AddRange(Model.GenTable.Columns.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    if (Model.GenTable.SubTable != null && Model.GenTable.SubTableName.IsNotEmpty())
    {
        dicts.AddRange(Model.GenTable?.SubTable?.Columns?.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    }
}
@foreach(var column in formCols)
{
    var labelName = "";
    var labelDisabled = "";
    var columnName = column.CsharpFieldFl;
    var value = "item.dictValue";
    if(column.FieldDesc != "")
    {
        labelName = column.FieldDesc;
    }
    else
    {
        labelName = column.CsharpFieldFl;
    }
    if(column.IsPk == true)
    {
        continue;
        labelDisabled = ":disabled=true";
    }
    if(column.CsharpType == "int" || column.CsharpType == "long")
    {
        value = "parseInt(item.dictValue)";
    }

    if (CodeGeneratorTool.CheckInputDtoNoField(column.CsharpField))
    {

    }
    else if (column.IsInsert == false && column.IsEdit == false)
    {
        continue;
    }
    else if(genTableOptions.IsTreeTable && genTableOptions.TreeTableNodePaIdField==column.CsharpField && genTableOptions.LeftTreeComponent=="self")
    {
@:<el-col :lg="12">
    @:<el-form-item label="@(labelName)" prop="@(columnName)">
        @:<treeselect v-model="form.@(columnName)" 
        @::options="@(funcCodeFirstLower)TreeFormOptions" 
        @::normalizer="normalizer"
        @::show-count="true" 
        @::no-options-text="noOptionsText"
        @::no-children-text="noChildrenText"
        @::no-results-text="noResultsText"
        @::loading-text="loadingText"
        @:placeholder="请选择@(labelName)" />
    @:</el-form-item>
@:</el-col>
    }
    else if (CodeGeneratorTool.CheckTree(genTable, column.CsharpField))
    {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <treeselect v-model="form.@(columnName)" 
            :options="dataList" 
            :normalizer="normalizer" 
            :show-count="true" 
            :no-options-text="noOptionsText"
            :no-children-text="noChildrenText"
            :no-results-text="noResultsText"
            :loading-text="loadingText"
            placeholder="选择@(labelName)" />
    </el-form-item>
</el-col>
    }
    else if (column.IsPk || column.IsIncrement)
    {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        @if (column.IsIncrement == false)
        {
            <el-input-number v-model.number="form.@(columnName)" controls-position="right" placeholder="请输入@(labelName)" :disabled="title=='修改数据'"/>
        }
        else
        {
            @:<span v-html="form.@(columnName)"/>
        }
    </el-form-item>
</el-col>
    }
    else
    {
        if (column.HtmlType == "text")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)">{{form.@(columnName)}}</el-form-item>
</el-col>
        }
        else if (column.HtmlType == "inputNumber")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-input-number v-model.number="form.@(columnName)" controls-position="right" placeholder="请输入@(labelName)" @(labelDisabled)/>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "datetime")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-date-picker v-model="form.@(columnName)" type="datetime" placeholder="选择日期时间"></el-date-picker>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "imageUpload")
        {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <UploadImage v-model="form.@(columnName)" column="@(columnName)" @@input="handleUploadSuccess" />
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "fileUpload")
        {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <UploadFile v-model="form.@(columnName)" column="@(columnName)" @@input="handleUploadSuccess" />
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "radio")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-radio-group v-model="form.@(columnName)">
            <el-radio v-for="item in @(column.DictType != ""?column.DictType:$"{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="@(value)">{{item.dictLabel}}</el-radio>
        </el-radio-group>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "radioBtn")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-radio-group v-model="form.@(columnName)">
            <el-radio-button v-for="item in @(column.DictType != ""?column.DictType:$"{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="@(value)">{{item.dictLabel}}</el-radio-button>
        </el-radio-group>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "textarea")
        {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-input type="textarea" v-model="form.@(columnName)" placeholder="请输入@(labelName)"/>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "editor")
        {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <editor v-model="form.@(columnName)" :min-height="200" />
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "select")
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-select v-model="form.@(columnName)" placeholder="请选择@(labelName)">
            <el-option v-for="item in @(column.DictType != ""?column.DictType:$"{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="item.dictLabel" :value="@(value)"></el-option>
        </el-select>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "checkbox")
        {
<el-col :lg="24">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-checkbox-group v-model="form.@(columnName)Checked">
            <el-checkbox v-for="item in @(column.DictType != ""?"options.@(column.DictType}":$"options.{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
        </el-checkbox-group>
    </el-form-item>
</el-col>
        }
        else if(column.HtmlType == "icon")
        {
@:<el-col :lg="24" >
    @:<el-form-item label="@(labelName)" prop="@(columnName)">
            @:<el-popover placement="bottom-start" width="460" trigger="click" @@show="$refs['@(columnName)IconSelect'].reset()">
                @:<IconSelect ref="@(columnName)IconSelect" @@selected="@(columnName)IconSelected" />
                @:<el-input slot="reference" v-model="form.icon" placeholder="点击选择图标" clearable="" readonly>
                        @:<svg-icon v-if="form.@(columnName)" slot="prefix" :icon-class="form.@(columnName)" class="el-input__icon" style="height: 32px; width: 16px" />
                        @:<i v-else slot="prefix" class="el-icon-search el-input__icon"></i>
                @:</el-input>
            @:</el-popover>
    @:</el-form-item>
@:</el-col>
        }
        else if(column.HtmlType=="customCtl")
        {
            string treeTitle = null;
@:<el-col :lg="12">
    @:<el-form-item label="@(labelName)" prop="@(columnName)">
            @switch (column.CustomCtl)
            {
                case "deptTreeSelect":
                    treeTitle = "部门";
                    break;
                case "companyTreeSelect":
                    treeTitle = "公司";
                    break;
                case "orgDepartTreeSelect":
                    treeTitle = "部门";
                    break;
                default:
                    break;
            }
            if(!string.IsNullOrWhiteSpace(treeTitle))
            {
            <treeselect v-model="form.@(columnName)" 
                :options="@(column.CustomCtl)FormOptions" 
                :show-count="true" 
                :normalizer="normalizer"
                :flat="true" 
                :no-options-text="noOptionsText"
                :no-children-text="noChildrenText"
                :no-results-text="noResultsText"
                :loading-text="loadingText"
                @@select="handle@(column.CustomCtl)Selected"
                placeholder="请选择@(treeTitle)" />
            }
    @:</el-form-item>
@:</el-col>
        }
        else
        {
<el-col :lg="12">
    <el-form-item label="@(labelName)" prop="@(columnName)">
        <el-input v-model="form.@(columnName)" placeholder="请输入@(labelName)" @(labelDisabled)/>
    </el-form-item>
</el-col>
        }
    }
}